﻿#nullable enable

namespace PHMEE.EnergyEfficiency;

/// <summary>
/// 公式 2
/// </summary>
public static class CIIFormulas
{
    /// <summary>
    /// 瞬时 CII 公式
    /// </summary>
    /// <param name="qmjship"></param>
    /// <param name="cfj"></param>
    /// <param name="capacity"></param>
    /// <param name="d"></param>
    /// <returns></returns>
    public static float? InstantaneityCIIUnAdjusted(float[] qmjship, float[] cfj, float capacity, float d)
    {
        if (qmjship.Length != cfj.Length)
        {
            return null;
        }

        float numerator = 0f;
        for (int j = 0; j < cfj.Length; j++)
        {
            numerator  += qmjship[j] * 1e6f * cfj[j];
        }
        
        var denominator = capacity * d;

        if (denominator == 0)
        {
            return null;
        }

        float cii = numerator  / denominator;
        
        return cii;
    }
}